package com.axisdesign.client;

import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class SubContentPanel extends HorizontalPanel {
	static public final int menuImage=15;
	static public final int typeImage=5;
	int menuStatus=0;
	
	VerticalPanel menuPanel;
	SubContentRightPanel subContentRightPanel[];
	
	String name;
	
	Image menuPanelImageTop;
	FlipImage menuPanelImage[];
	Image menuPanelImageBottom;
	
	public SubContentPanel(String _name,int _menuStatus,int type) {
		name = _name;
		menuStatus = _menuStatus;
		
		menuPanel = new VerticalPanel();
		subContentRightPanel = new SubContentRightPanel[menuImage];
		menuPanelImage = new FlipImage[menuImage];
		
		init(type);
	}
	
	private void init(int type) {		
		queue(menuStatus,type);
		
		for(int i=0; i<menuImage; i++) {
			final int menu = i;
			menuPanelImage[i].addClickListener(new ClickListener() {public void onClick(Widget sender) {queue(menu, 0);}});
		}
	}
	
	public void queue(int menu,int type) {
		clear();
		queueMenuImage(menu);
		queueContent(menu, type);
		
		add(menuPanel);
		add(subContentRightPanel[menuStatus]);
	}
	
	private void queueMenuImage(int menu) {
		menuStatus = menu;
		if(menuPanelImageTop == null) {
			menuPanelImageTop = new Image("images/mainFrame/content/subContent/"+name+"/menupanelimagetop.png");
			menuPanel.add(menuPanelImageTop);
		}

		for(int i=0; i<menuImage; i++) {			
			if(menuPanelImage[i] == null ) {
				menuPanelImage[i] = new FlipImage(
						new Image("images/mainFrame/content/subContent/"+name+"/menupanelimage"+i+"_a.png")
						,new Image("images/mainFrame/content/subContent/"+name+"/menupanelimage"+i+"_b.png")
						,false
				);
				menuPanel.add(menuPanelImage[i]);
			}
			menuPanelImage[i].setImage1Default((menuStatus==i)?false:true);
		}
		
		if(menuPanelImageBottom == null) {
			menuPanelImageBottom = new Image("images/mainFrame/content/subContent/"+name+"/menupanelimagebottom.png");
			menuPanel.add(menuPanelImageBottom);
		}
	}
	
	private void queueContent(int menu,int type) {
		menuStatus=menu;
		if(subContentRightPanel[menuStatus] == null) {
			subContentRightPanel[menuStatus] = new SubContentRightPanel(name,menuStatus,type);
			subContentRightPanel[menuStatus].setStyleName("subContentRightPanel");
		}
		else {
			subContentRightPanel[menuStatus].queue(type);
		}
	}
}
